package net.htjs.juc.thread;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ThreadLocalDemo {

    private static ThreadLocal<String> threadLocal = ThreadLocal.withInitial(() -> "初始值");

    public static void main(String[] args) {
        new Thread(() -> {
            threadLocal.set("线程1设置的值");
            log.info("threadName:{}：获取的值{}", Thread.currentThread().getName(), threadLocal.get());
        }).start();

        new Thread(() -> {
            log.info("threadName:{}：获取的值{}", Thread.currentThread().getName(), threadLocal.get());
        }).start();
    }


}
